import { _decorator, Component, Node,Animation ,
RigidBody2D,
Vec2,
UITransform,
Collider2D,
Contact2DType,
IPhysics2DContact

} from 'cc';
import { TabEnum } from '../enum';
const { ccclass, property } = _decorator;

@ccclass('fly')
export class fly extends Component {

    @property(Number)
    flyY:number = 5
    start() {
        // let ani = this.node.getComponent(Animation)
        // ani.play("fly")

        /**
         * 监听碰撞
         */
        const collider = this.getComponent(Collider2D);
        if(collider){
            collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
        }
    }
    onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D,
        contact: IPhysics2DContact | null) {
     
       if(otherCollider.tag == TabEnum.pipe){
           // director.loadScene('gameOver')
           //销毁自身
           console.log('object :>> 销毁自身',);
        //    this.node.destroy()
        //    otherCollider.node.getComponent(enemyContral).die()

       }else if(otherCollider.tag == TabEnum.add){
           // director.loadScene('gameOver')
         console.log('object :>> 加分了',);
       }
   }
    /**
     * 飞行方法
     */
    flyPlay(count:number){
       let flyRightBody =  this.node.getComponent(RigidBody2D)
       flyRightBody.linearVelocity = new Vec2(0,this.flyY+(count/5))
        
    }
    update(deltaTime: number) {
        
    }
}


